package com.gutsyzhan.activitifly;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
public class Part2_ProcessDefinition {
    @Resource
    private RepositoryService repositoryService;
    /**
     * 查询流程定义
     */
    @Test
    public void getDefinitions() {
        List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery().list();
        for (ProcessDefinition definition : definitions) {
            System.out.println("Key:" + definition.getKey());
            System.out.println("Name:" + definition.getName());
            System.out.println("DeploymentId:" + definition.getDeploymentId());
            System.out.println("Version:" + definition.getVersion());
            System.out.println();
        }
    }

    /**
     * 删除流程定义
     */
    @Test
    public void deleteDefinition() {
        String deploymentId = "";
        //值为true表示删除该流程定义下面所有的流程实例、任务以及历史
        //值为false表示保留历史，只删除当前正在使用的流程定义实例，之前的历史任务是不会删除
        repositoryService.deleteDeployment(deploymentId, false);
        System.out.println("删除流程定义成功");
    }
}
